lib-manager: validate ELF sizes and offsets#10899
Open
lyakh wants to merge 1 commit into
Open
Conversation
The library manager loads ELF files from the host file-system. Those files have to be only root-writable, so they are relatively trust- worthy - if you're root, it's anyway "game over." Still it's good to verify for corrupt or maniputalte invalid ELF images. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens the library manager’s ELF module loading by validating segment sizes/offsets against the loaded library image to prevent out-of-bounds reads.
Changes:
- Add overflow-safe size calculation for segment load sizes and validate segments stay within the preloaded library image.
- Thread the firmware descriptor (
desc) into allocation/loading paths to access total image size. - Add bounds-check logging for invalid segment metadata.
| * ELF file segment offsets and sizes come from library files, so they | ||
| * have to be validated. | ||
| */ | ||
| const size_t lib_size = (size_t)desc->header.preload_page_count * PAGE_SZ; |
Comment on lines
+180
to
+183
| if (size_mul_overflow(mod->segment[idx].flags.r.length, PAGE_SZ, &size)) { | ||
| ret = -EOVERFLOW; | ||
| goto err; | ||
| } |
| src = UINT_TO_POINTER(file_offset + load_offset); | ||
| va_base = (void __sparse_cache *)UINT_TO_POINTER(mod->segment[idx].v_base_addr); | ||
| size = mod->segment[idx].flags.r.length * PAGE_SZ; | ||
| ret = lib_manager_load_data_from_storage(va_base, src, size, flags); |
| goto err; | ||
| } | ||
|
|
||
| src = UINT_TO_POINTER(file_offset + load_offset); |
Comment on lines
+188
to
+190
| "segment %d out of bounds: file_offset %#x, size %#zx, total %#zx", | ||
| idx, file_offset, size, lib_size); | ||
| ret = -ENOSPC; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The library manager loads ELF files from the host file-system. Those files have to be only root-writable, so they are relatively trust- worthy - if you're root, it's anyway "game over." Still it's good to verify for corrupt or maniputalte invalid ELF images.